package com.ruoyi.controller;

import com.camp.domain.CYd;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;


import com.ruoyi.dmain.WxLoginUser;
import com.ruoyi.service.IWxLoginService;
import com.ruoyi.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信登录控制器
 * @auth zhaoly
 * @date 2024-01-25 10:16
 */
@Anonymous
@RestController
@RequestMapping("/wechart")
public class WxLoginController extends BaseController {
@Autowired
private ThreadLocalUtil threadLocalUtil;
    @Autowired
    private IWxLoginService loginService;



    /**
     * 小程序登录
     * @param code 微信预登录code
     * @param userName 登录用户名
     * @param password 登录密码
     * @return
     */
    //登录
    @PostMapping("/login")
    public AjaxResult wxCodeLogin( @RequestParam(name = "avatarUrl") String imgurl,String code, @RequestParam(value = "nickName")String userName, String password){

        WxLoginUser user = loginService.login(imgurl,code, userName, password);

        System.out.println("00000000000");
        System.out.println(user);
//        threadLocalUtil.set(user.getUserId());
//        String s = threadLocalUtil.get();
//        System.out.println(s);
        return user.getStatus() >= 0 ? success(user) : error(user.getMsg());
//        return AjaxResult.success("www");
    }






}